/**
 * Copyright (C), 2024, Y2 T205
 * FileName: ch01_02
 * Author: Lenovo
 * Date: 2024-01-12 15:11
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */


package com.example.multithreading;


import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.concurrent.TimeUnit;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author Lenovo
 * @create 2024-01-12
 * @since 1.0.0
 */
@SpringBootTest
public class ch01_02 {

    @Test
    public void test(){

        Thread thread = new Thread() {
            @Override
            public void run() {
                watchTV();
            }
        };
        thread.start();
        listenMusic();
    }

    private void listenMusic() {
        for (int i = 0; i < 10; i++) {
            System.out.println("我正在听歌");
            sleep(1);
        }
    }

    public void watchTV(){
        for (int i = 0; i < 10; i++) {
            System.out.println("我正在看电视");
            sleep(1);
        }
    }
    public void sleep(int seconds){
        try {
            TimeUnit.SECONDS.sleep(seconds);
        } catch (InterruptedException e) {
            System.out.println("出现异常");
        }
    }

}
